package cn.laixueit.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class UserController {


    @GetMapping("/index")
    public String index(){

        return "index";
    }

    @PostMapping("/login")
    public String login(String username, String pwd, HttpServletRequest request){
        HttpSession session = request.getSession();
        if("admin".equals(username)){
            session.setAttribute("userName",username);
        }
        return "main";
    }

    @GetMapping("/logout")
    public String logout(HttpServletRequest request){
        HttpSession session = request.getSession();
        session.removeAttribute("userName");
        return "index";
    }
}
